// 这是历史热门组件
<template>
  <div class="historyComponent">
    <div class="history-hot">
      <div class="hot-top">
        <h6>历史记录</h6>
        <van-icon name="delete" @click="clearHistory"/>
      </div>
      <div class="hot-bottom" v-show="isShowHistory">
        <van-tag @click="tagClick(item)" v-for="(item, index) in historyListData" :key="index" size="large" type="primary">{{item}}</van-tag>
      </div>
    </div>
    <div class="history-hot">
      <div class="hot-top">
        <h6>热门搜索</h6>
      </div>
      <div class="hot-bottom">
        <van-tag
          @click="tagClick(item.keyword)"
          :class="item.is_hot ? 'hotkey' : ''" v-for="(item, index) in hotKeywordListData"
          :key="index"
           size="large"
           type="primary">{{item.keyword}}</van-tag>
      </div>
    </div>
  </div>
</template>

<script>
import { ClearHistory } from '@/utils/api.js'
export default {
  name: 'HistoryHot',
  components: {},
  props: [
    // 接受父组件传值
    'historyListData',
    'hotKeywordListData'
  ],
  data () {
    return {
      isShowHistory: true // 是否显示历史记录
    }
  },
  computed: {},
  created () {},
  mounted () {},
  watch: {},
  methods: {
    tagClick (value) { // 历史记录 tag 点击事件
      // 标签 点击函数，value 为选择的 value 值
      this.$emit('tagClick', value) // 向父组件 SearchPopup 传递 tagClick 方法
    },
    clearHistory () { // 清除历史记录
      ClearHistory().then(response => {
        if (response.errno === 0) {
          this.$toast.success('删除成功') // Toast 轻提示
          this.isShowHistory = false // 关闭历史记录
        }
      }).catch(error => {
        console.log(error)
      })
    }
  }
}
</script>

<style scoped lang='less'>
.historyComponent{
  background-color: #c0c0c0;
  .center{
    height: .5rem;
  }
}
.history-hot{
  padding: .2rem;
  margin-bottom: .5rem;
  background-color: #cccccc;
  .hot-top{
    display: flex;
    justify-content: space-between;
    font-size: .6rem;
  }
  .hot-bottom{
    .van-tag{
      // padding: 0.05rem;
      margin: 0.081rem;
      border-radius: 0.15rem;
      box-shadow: 0 0 5px 1px rgba(0, 0, 0, .36)
    }
  }
  .hotkey{
    color: yellow;
  }
}
</style>
